package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseCategory1;
import com.atguigu.gmall.model.product.BaseCategory2;
import com.atguigu.gmall.model.product.BaseCategory3;
import com.atguigu.gmall.product.service.BaseCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author 卡尼奶
 * @Date 2022/5/17 19:40
 * @Version 1.0
 */
@RestController
@RequestMapping("/admin/product")
public class BaseCategoryController {

    @Autowired
    private BaseCategoryService categoryService;

    /**
     * 获取所有商品一级分类
     * @return
     */
    @GetMapping("/getCategory1")
    public Result getCategory1(){
        List<BaseCategory1> category1s = categoryService.getCategory1();
        return Result.ok(category1s);
    }

    /**
     * 查询一级分类下的二级分类信息
     * @param category1Id
     * @return
     */
    @GetMapping("/getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable("category1Id")Long category1Id){
        List<BaseCategory2> category2s = categoryService.getCategoryByC1(category1Id);
        return Result.ok(category2s);
    }
    /**
     * 查询二级分类下的三级分类信息
     * @param category2Id
     * @return
     */
    @GetMapping("/getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable("category2Id")Long category2Id){
        List<BaseCategory3> category3s = categoryService.getCategoryByC2(category2Id);
        return Result.ok(category3s);
    }
}
